package com.relatev.minecraft.UWantRestart;

import java.util.Calendar;

public class RestartCondition {

    public RestartCondition(int minhour, int maxhour, int maxplayer) {
        MinHour = minhour;
        MaxHour = maxhour;
        MaxPlayer = maxplayer;
    }

    public final int MinHour;
    public final int MaxHour;
    public final int MaxPlayer;
    public boolean StartIgnore;

    public boolean meetCondition(int playercount) {
        if (StartIgnore == false) {
            Calendar cal = Calendar.getInstance();
            if (MinHour <= MaxHour) {
                if (MinHour <= cal.get(Calendar.HOUR_OF_DAY) && cal.get(Calendar.HOUR_OF_DAY) < MaxHour) {
                    return playercount <= MaxPlayer;
                } else {
                    return cal.get(Calendar.HOUR_OF_DAY) == MaxHour;
                }
            } else {
                if (MinHour <= cal.get(Calendar.HOUR_OF_DAY) || cal.get(Calendar.HOUR_OF_DAY) < MaxHour) {
                    return playercount <= MaxPlayer;
                } else {
                    return cal.get(Calendar.HOUR_OF_DAY) == MaxHour;
                }
            }
        }
        return false;
    }
    
    @Override
    public String toString(){
        return "§a" + MinHour + "§r-§c" + MaxHour + " §r| §b" + MaxPlayer;
    }
}
